//
//  SecondViewControlelr.swift
//  swiftDemo
//
//  Created by zhangjianyun on 17/6/28.
//  Copyright © 2017年 com.taihejiacheng. All rights reserved.
//

import Foundation
import UIKit

//定义一个协议
protocol FontSizeChangeDelegate {
    // 定义一个协议函数
    func fontSizeChange(controller: SecondViewControlelr, fontSize: Int)
}

class SecondViewControlelr: UIViewController {
    
    var fontSize: Int = 15;
    
    var delegate: FontSizeChangeDelegate?
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.backgroundColor = UIColor.red
         
        let b: UIButton = UIButton.init(type: UIButtonType.system)
        let frame = CGRect.init(x: 100, y: 100, width: 100, height: 40)
        b.frame = frame
        b.setTitle("返回", for: UIControlState.normal)
        b.backgroundColor = UIColor.red
        b.addTarget(self, action: #selector(self.didClickOnBackBtn(sender:)), for: UIControlEvents.touchUpInside)
        self.view!.addSubview(b)
        
        let button = UIButton.init(type: UIButtonType.custom)
        button.frame = CGRect(x:0,y:300,width:100,height:40);
        button.setTitle("增大", for: UIControlState.normal)
        button.backgroundColor = UIColor.black
        button.addTarget(self, action: #selector(self.ClickMe(sender:)), for: UIControlEvents.touchUpInside)
        self.view!.addSubview(button)

        
    }
    
    func didClickOnBackBtn(sender: UIButton) {
        self.navigationController!.popViewController(animated: true)
    }
    
    func ClickMe(sender: UIButton) {
        fontSize += 1
        print("fontSize is \(fontSize)")
        
        if (delegate != nil) {
            delegate!.fontSizeChange(controller: self, fontSize: fontSize)
        }
    }
}
